<script setup lang="ts">
import DisableDevtool from 'bian-disable-devtool';
import { RouterView, useRouter } from 'vue-router'
import autofit from 'autofit.js'
import { onMounted, onUnmounted } from 'vue';
import { debounce } from 'lodash';
import { useUserStore } from './stores/user';
import { ElMessageBox } from "element-plus";
let router = useRouter();
let userStore = useUserStore();
// 退出登录事件
function handleAltQ(event: KeyboardEvent) {
  // 空格键进行全盘和非全盘切换
  if (event.key === ' ') {
    if (document.fullscreenElement) {
      document.exitFullscreen();
    } else {
      const element = document.documentElement;
      element.requestFullscreen();
    }
  }
  // 按住Alt + Q键并登录时，退出登录
  if (event.ctrlKey && event.key === 'q' && userStore.isLogin) {
    event.preventDefault(); // 阻止默认行为
    ElMessageBox.confirm(
      '即将退出登录，是否继续?',
      '警告',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
    ).then(() => {
      /**
       * @TODO 此处应做退出登录操作
       */
      userStore.clearUserInfo(router);
    }).catch((err) => {

    })
  }
}
const handleAltQDebounced = debounce(handleAltQ, 200);
onMounted(() => {
  // 禁用f12打开控制台
  DisableDevtool({
    interval: 1000,
    ignore: () => {
      return import.meta.env.MODE === 'development' || import.meta.env.MODE === 'test'; // 当是管理员时忽略禁用
    }
  });
  document.addEventListener('keydown', handleAltQDebounced);
})
onUnmounted(() => {
  document.removeEventListener('keydown', handleAltQ);
})
// 大屏适配
autofit.init({
  dh: 1080,
  dw: 1920,
  el: "#app",
  resize: true,
  transition: 0.3,
  delay: 150
},
  false // 可关闭控制台提示输出
)

</script>

<template>
  <RouterView />
</template>
